package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.AddFamilyDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.*;

import io.swagger.annotations.Api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;

import com.zzyl.nursing.service.IFamilyMemberService;


/**
 * 老人家属Controller
 * 
 * @author alexis
 * @date 2025-01-09
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto){
       LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
       return R.ok( loginVo);
    }

    /**
     * 1.1 绑定家人
     * @param familyDto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addFamily(@RequestBody  AddFamilyDto familyDto){
        Integer i = familyMemberService.addFamily(familyDto);
        if(i!=1){
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    /**
     * 1.2 查询家人列表
     * @return
     */
    @GetMapping("/my")
    public R<List<FamilyMemberElderVo>> getMyFamily(){
        List<FamilyMemberElderVo> list=familyMemberService.getMyFamily();
        return R.ok(list);
    }
    @GetMapping("/list-by-page")
    public R<List<ListByPageVo>> listByPage(@RequestParam(required = false) Integer pageNum, @RequestParam(required = false)  Integer pageSize){
        List<ListByPageVo> list=familyMemberService.listByPage(pageNum, pageSize);
        return R.ok(list);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    public R<ListVo> queryDevicePropertyStatus(@RequestBody Device device){
        String deviceName = device.getDeviceName();
        String productKey = device.getProductKey();
        List<PropertyStatusInfoVo> list=familyMemberService.queryDevicePropertyStatus(deviceName, productKey);

        ListVo listVo=new ListVo();
        listVo.setPropertyStatusInfoVo(list);
        return R.ok(listVo);
    }
}
